// let app = getApp()
let observerComponment = require("../../common/lib/observer").observerComponment
let store = require("./cb_item_store").store

Component(observerComponment({
	props: {
		// common_store: app.data.common_store,
		store: store
	},
	data: {

	},
	properties: {
		word: {
			value: "",
			type: String,
		},
		input: {
			type: String,
			value: "",
			observer: function(n) {
				this.check_input()
			}
		},
		current: {
			type: String,
			value: "0",
			observer: function(n) {
				this.check_current()
			}
		}
	},
	lifetimes: {
		ready: function () {
			console.log(this.props)
		}
	},
	methods: {
		check_current() {
			// console.log(this.data.current)
			if(this.data.current == "1") {
				this.props.store.current_color = this.props.store.green
			}
			else if (this.data.current == "0") {
				// this.check_input()
				this.props.store.current_color = this.props.store.gray
			}
		},
		check_input() {
			if(this.data.input == "") {
				this.props.store.show_word = "*"
				this.props.store.current_color = this.props.store.gary
			}
			else {
				this.props.store.show_word = this.data.input
				// 输入正确
				if (this.data.input == this.data.word) {
					this.props.store.current_color = this.props.store.blue
				}
				else {
					this.props.store.current_color = this.props.store.red
				}
			}
		}
	}
}))